#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Main menu"""

import sunflow
from PySFML import *
import gui

def run():
    """Run the main menu."""
    running = True
    event = sf.Event()
    
    backgroundImage = sf.Image()
    backgroundImage.LoadFromFile("share/background.png")
    background = sf.Sprite(backgroundImage, 0, 0)
    
    columns = gui.HBox()
    columns.add(gui.PlaceHolder(), 1)
    
    menuContainer = gui.VBox()
    menuContainer.add(gui.Button("SunFlow", sunflow.font, 80), 1)
    
    menu = gui.HBox()
    menu.add(gui.PlaceHolder(), 1)
    
    menuItems = gui.VBox()
    menuItems.add(gui.PlaceHolder(), 2)
    menuItems.add(gui.Button(_("New game"), sunflow.font, 40), 4)
    menuItems.add(gui.Button(_("Settings"), sunflow.font, 40), 4)
    menuItems.add(gui.Button(_("Credits"), sunflow.font, 40), 4)
    menuItems.add(gui.PlaceHolder(), 1)
    menuItems.add(gui.Button(_("Quit"), sunflow.font, 40), 4)
    menuItems.add(gui.PlaceHolder(), 2)
    menu.add(menuItems, 4)
    menu.add(gui.PlaceHolder(), 1)
    
    menuContainer.add(menu, 4)
    
    columns.add(menuContainer, 5)
    columns.add(gui.PlaceHolder(), 1)
    
    
    page = gui.Page((sunflow.screenSize[0] / 16, sunflow.screenSize[1] / 16, sunflow.screenSize[0] / 16 * 14, sunflow.screenSize[1] / 16 * 14), columns)
    page.compute()
    
    while running:
        while sunflow.window.GetEvent(event):
            if event.Type == sf.Event.Closed:
                running = False
            if event.Type == sf.Event.KeyPressed:
                if event.Key.Code == sf.Key.Escape:
                    running = False
            page.process_event(event)
        
        sunflow.window.Draw(background)
        page.draw(sunflow.window)
        sunflow.window.Display()
